import { ref, computed } from 'vue';
import { useInitDataSingleton } from './shared';
import { SysUserApi, SysUserAllOutput } from '/@/api/bas/sysUser';

const { list, initList: initUserList } = useInitDataSingleton<SysUserAllOutput>(SysUserApi.all);

// 用户信息, 必须在登录后初始化
export { initUserList };

// 输血科用户列表
export const userList4ShuXueKe = computed(() => {
	return list.value.filter((item) => item.orgId == 1300000000002 || item.orgPid == 1300000000002) ?? [];
});

export const userList = computed(() => {
	return list.value.filter((item) => item.orgId > 0) ?? [];
});

// 根据id获取用户姓名
export function getUserName(id: number) {
	if (id == undefined) return '';
	let obj = list.value.find((item) => item.id == id);
	return obj?.realName ?? '';
}
/** 根据id获取用户工号 */
export function getUserAccount(id: number) {
	if (id == undefined) return '';
	let obj = list.value.find((item) => item.id == id);
	return obj?.account ?? '';
}
